package com.ljy.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljy.job.domain.JobInfo;
import com.ljy.job.service.JobInfoService;
import com.ljy.job.mapper.JobInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 */
@Service
public class JobInfoServiceImpl extends ServiceImpl<JobInfoMapper, JobInfo> implements JobInfoService{

    @Autowired
    JobInfoMapper mapper;

    @Override
    @Transactional
    public boolean save(JobInfo info) {
        //查数据库是否有记录
        List<JobInfo> list = mapper.selectList(new QueryWrapper<JobInfo>().eq("url", info.getUrl()));
        if (list.size() > 0){
            String time = list.get(0).getTime();

            //检查发布日期是否为最新的
            if (info.getTime().equals(time)){
                return true;
            }else {
                //更新数据
                info.setId(list.get(0).getId());
                updateById(info);
                return true;
            }
        }
        //保存
        return super.save(info);
    }
}




